var { getLoginedUser, fnLoading, fnHideLoading, fnSuccess, fnFail} = require('../../utils/index')
import { domainStatic } from '../../utils/env.js';
import _ from '../../utils/underscore.js';
import { get, fnChoose, lsGetStr, lsSetStr,fnUpload, post } from '../../utils/request.js';
// pages/means/index.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    userName:"",
  tel:"",
  email:"",
  },
  phoneInput(e){
    let key = e.currentTarget.dataset.name,
     value = e.detail.value,
     obj = {};
    obj[key] = value;
    this.setData(obj)
},
  button:function(e){
        let that=this;
          fnLoading("提交中...");
    var updateData = {
      skey: lsGetStr("skey"),
      country: that.data.country,
      userName: that.data.userName,
      phone: that.data.phone,
      id: that.data.id
    };
        post({
          path:"/user/update",
          data: updateData
        }).then(function(res){
          lsSetStr('loginedUser', JSON.stringify(Object.assign({},
            that.data.user || {}, updateData
          )));
          setTimeout(function () {
            fnHideLoading();
            wx.navigateBack({
              delta: 1,
            });
          },1500)
        })
    },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that=this;
    get({
      path: "user/getInfo"
    }).then(function (res) {
      // console.log(res)
      that.setData({
        user: res.user,
        phone: res.user.phone || '',
        country: res.user.country || '',
        options: options,
        userName: res.user.nickName || '',
        id: res.user.id,
      })
    })
  },
})